# https://leetcode.cn/problems/minimum-number-of-days-to-make-m-bouquets/description/
# 1482. 制作 m 束花所需的最少天数
# medium, 刘小康 2024.09.13
# 二分查找

class Solution:
    def minDays(self, bloomDay: list[int], m: int, k: int) -> int:

        # 特殊条件
        if m * k > len(bloomDay):
            return -1

        # 开始
        left = 1
        right = 2147483647
        while left < right:     # 下界

            mid = left + ((right - left) >> 1)

            m_tmp = 0
            k_tmp = 0
            for it in bloomDay:

                if mid >= it:
                    k_tmp += 1
                else:
                    k_tmp = 0

                # 够一束
                if k_tmp == k:
                    m_tmp += 1
                    k_tmp = 0

            if m_tmp >= m:
                right = mid
            else:
                left = mid + 1

        return left
